package com.itheima.text5;

public class Box {
   private int count;

   private boolean flag = false;

   public  synchronized void put(int count){
      if (flag){
         try {
            wait();
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }

      this.count = count;
      System.out.println("送奶工送奶");

      flag = true;

      notifyAll();
   }

   public synchronized  void get(){
      if (!flag){
         try {
            wait();
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }

      System.out.println("用户拿到奶");

      flag = false;

      notifyAll();
   }
}
